/**
 * @asignatura: Procesadores de Lenguajes.
 * @autor:      Anthony Vittorio Russo Cabrera
 * @curso:      2012/2013
 * @practica:   05 - FLEX
 * @descripcion:
 */
package pl.p05;

import java.io.FileNotFoundException;
import java.io.IOException;

import org.antlr.runtime.ANTLRStringStream;
import org.antlr.runtime.CommonTokenStream;
import org.antlr.runtime.RecognitionException;

import pl.p05.case_insensitivity.ANTLRFileStreamCaseInsensitivity;
import pl.p05.case_insensitivity.ANTLRInputStreamCaseInsensitivity;

public class Procesador {

  public static void main(String args[]) {
    // Determinar parámetros
    ANTLRStringStream input = null;
    FlexLexer lexer = null;
    FlexParser parser = null;
    CommonTokenStream tokens;
    try {
      switch (args.length) {
        case 0: // InputStream
          input = new ANTLRInputStreamCaseInsensitivity(System.in);
          break;
        case 1: // FileStream
          input = new ANTLRFileStreamCaseInsensitivity(args[0]);
          break;
        default:
          System.err.println("java Procesador (file)?");
          System.exit(0);
      }// switch

      // Núcleo de la práctica
      lexer = new FlexLexer(input);
      tokens = new CommonTokenStream(lexer);
      parser = new FlexParser(tokens);
      parser.rulesFlex();
      
    // Execpciones
    } catch (FileNotFoundException e) {
      System.err.println("File Not Found: \"" + args[0] + "\"");
      e.printStackTrace();
    } catch (IOException e) {
      System.err.println("Input/Output Error");
      e.printStackTrace();
    } catch (RecognitionException e) {
      System.err.println("Parser Error");
      e.printStackTrace();
    }// try-catch

  } // main

}// Procesador
